import React, { Component } from 'react'
import './index.less'
import { Form, Input, Button, message } from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';
// import cookie from 'react-cookies';
import{adminLogin}from '../api/api'
export default class admin extends Component {
  
  onFinish = (values) => {
      console.log('Success:', values);
      adminLogin({adminName:values.adminName , adminPassword:values.adminPassword}).then(res=>{
        if(res.code===20000){
          sessionStorage.setItem("yiQingToken",res.data)
        }
      })
      if(values.adminName==="admin" && values.adminPassword==="Hhxy@xxhbgs5"){
        this.props.history.push('/index')
        message.success('登录成功！');
      }else{
        message.error('用户名或密码不正确');
      }
    };

  render() {
    return (
      <div className="Index">
        <div className="login">
          <div className="title">黄淮疫情大数据</div>
          <div className="user">
            <div className="user-login">用户登录</div>
            <Form
              name="normal_login"
              className="login-form"
              initialValues={{
                remember: true,
              }}
              onFinish={this.onFinish}
            >
              <Form.Item
                name="adminName"
                rules={[
                  {
                    required: true,
                    message: '请输入用户名!',
                  },
                ]}
              >
                <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="请输入用户名" />
              </Form.Item>
              <Form.Item
                name="adminPassword"
                rules={[
                  {
                    required: true,
                    message: '请输入密码!',
                  },
                ]}
              >
                <Input
                  prefix={<LockOutlined className="site-form-item-icon" />}
                  type="password"
                  placeholder="请输入密码"
                />
              </Form.Item>

              <Form.Item>
                <Button type="primary" htmlType="submit" className="login-form-button">
                  登录
                </Button>
              </Form.Item>
          </Form>
          </div>
        </div>
      </div>
    )
  }
}
